package com.wu.ssm.spring.core.impl;

import com.wu.ssm.spring.core.ClassScanner;
import com.wu.ssm.spring.core.impl.support.AnnotationClassTemplate;
import com.wu.ssm.spring.core.impl.support.SupperClassTemplate;

import java.lang.annotation.Annotation;
import java.util.List;

/**
 * Created by wzf on 2018/12/17/017.
 */
public class DefaultClassScanner implements ClassScanner {
    @Override
    public List<Class<?>> getClassList(String packageName) {
        return null;
    }

    @Override
    public List<Class<?>> getClassListByAnnotation(String packageName, Class<? extends Annotation> annotationClass) {
        return new AnnotationClassTemplate(packageName, annotationClass){
            @Override
            public boolean checkAddClass(Class<?> cls) {
                return cls.isAnnotationPresent(annotationClass);
            }
        }.getClassList();
    }

    @Override
    public List<Class<?>> getClassListBySuper(String packageName, Class<?> superClass) {
        return new SupperClassTemplate(packageName, superClass){
            @Override
            public boolean checkAddClass(Class<?> cls) {
                return superClass.isAssignableFrom(cls) && !superClass.equals(cls);
            }
        }.getClassList();
    }
}
